/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import DTO.LoaiGiaVe_DTO;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Phung
 */
public class LoaiGiaVe_DAO {
    
    public static ArrayList<LoaiGiaVe_DTO> GetALL()
    {
        ArrayList<LoaiGiaVe_DTO> ds = new ArrayList<>();
        try {
            String sql = "Select * from LoaiGiaVe" ;
            MySQLDataHelper_DAO.open();
            ResultSet rs =  MySQLDataHelper_DAO.executeQuery(sql);
            while (rs.next()) {
                LoaiGiaVe_DTO LoaiVe = new LoaiGiaVe_DTO();
                LoaiVe.setID(rs.getInt("ID"));
                LoaiVe.setLoaiVe(rs.getInt("LoaiVe"));
                LoaiVe.setTyLeGiam(rs.getDouble("TyLeGiam"));
                LoaiVe.setLoaiDT(rs.getInt("LoaiDT"));
                ds.add(LoaiVe);
            }
            MySQLDataHelper_DAO.close();
       }catch (SQLException ex) {
            System.out.println(ex);
        }
        return ds;
    }
    
    public static boolean Insert(LoaiGiaVe_DTO LoaiVe)
    {
        boolean flag = false;
        try {
            String sql = "Insert LoaiVe(LoaiVe,TyLeGiam,LoaiDT) Values('"+LoaiVe.getLoaiVe()+"','"+LoaiVe.getTyLeGiam()+"','"+LoaiVe.getLoaiDT()+"')";
            MySQLDataHelper_DAO.open();
            int kq = MySQLDataHelper_DAO.executeUpdate(sql);
            if(kq == 1)
                flag =true;
            MySQLDataHelper_DAO.close();
        }catch (Exception ex) {
            System.out.println(ex);
        }
        return flag;
    }
    
    public static boolean Update(LoaiGiaVe_DTO LoaiVe)
    {
        boolean flag = false;
        try {
            String sql = "Update LoaiGiaVe Set LoaiVe = "+ LoaiVe.getLoaiVe() +", TyLeGiam = "+LoaiVe.getTyLeGiam()+", LoaiDT = "+LoaiVe.getLoaiDT()+" where ID = "+ LoaiVe.getID();
            MySQLDataHelper_DAO.open();
            int kq = MySQLDataHelper_DAO.executeUpdate(sql);
            if(kq == 1)
                flag =true;
            MySQLDataHelper_DAO.close();
        }catch (Exception ex) {
            System.out.println(ex);
        }
        return flag;
    }
    
    public static boolean Delete(int maID)
    {
        boolean flag = false;
        try {
            String sql = "Delete from LoaiGiaVe where ID = "+ maID;
            MySQLDataHelper_DAO.open();
            int kq = MySQLDataHelper_DAO.executeUpdate(sql);
            if(kq == 1)
                flag =true;
            MySQLDataHelper_DAO.close();
        }catch (Exception ex) {
            System.out.println(ex);
        }
        return flag;
    }
    
}
